

# 自定义排行展示过滤器
from flask import current_app
from flask import session,g

from info.models import User



def index_class(index):
    if index == 1:
        return 'first'
    elif index == 2:
        return 'second'
    elif index == 3:
        return 'third'
    else:
        return ''


import functools

# 自定义登陆校验装饰器
def login_required(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        # cong redis 中查找user_id信息
        user_id = session.get('user_id')
        user = None
        # 判断user是否存在
        try:
            user = User.query.filter_by(id=user_id).first()
        except Exception as e:
            current_app.logger.error(e)
        # 用g变量存储user
        g.user = user
        return f(*args, **kwargs)
    return wrapper